package cn.edu.scau.cmi.chensicheng.comprehension.controller;

import java.io.IOException;

import cn.edu.scau.cmi.chensicheng.client.AbstractFactoryClient;
import cn.edu.scau.cmi.chensicheng.client.AdapterClient;
import cn.edu.scau.cmi.chensicheng.client.CompositeClient;
import cn.edu.scau.cmi.chensicheng.client.FactoryMethodClient;
import cn.edu.scau.cmi.chensicheng.client.HibernateClient;
import cn.edu.scau.cmi.chensicheng.client.MultitonClient;
import cn.edu.scau.cmi.chensicheng.client.SimpleFactoryMethodClient;
import cn.edu.scau.cmi.chensicheng.client.SingletonClient;
import cn.edu.scau.cmi.chensicheng.spring.client.SpringClient;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class Controller {
	@FXML
	private ImageView imageView;
	@FXML
	private Button singletonButton;
	@FXML
	private Button multitonButton;
	@FXML
	private Button simpleFactoryMethodButton;
	@FXML
	private Button factoryMethodButton;
	@FXML
	private Button springButton;
	@FXML
	private Button hibernateButton;
	@FXML
	private Button consistentCompositeButton;
	@FXML
	private Button abstractFactoryButton;
	@FXML
	private Button classAdapterButton;
	@FXML
	private Button safeCompositeButton;
	@FXML
	private Button objectAdapterButton;

	public void initialize() {
		imageView.setImage(new Image(getClass().getResourceAsStream("../../selfie.jpg")));
		singletonButton.setOnAction(e -> {
			new SingletonClient().start(new Stage());
		});
		multitonButton.setOnAction(e -> {
			new MultitonClient().start(new Stage());
		});
		simpleFactoryMethodButton.setOnAction(e -> {
			try {
				new SimpleFactoryMethodClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		factoryMethodButton.setOnAction(e -> {
			try {
				new FactoryMethodClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		abstractFactoryButton.setOnAction(e -> {
			try {
				new AbstractFactoryClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		objectAdapterButton.setOnAction(e -> {
			try {
				new AdapterClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		classAdapterButton.setOnAction(e -> {
			try {
				new AdapterClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		safeCompositeButton.setOnAction(e -> {
			try {
				new CompositeClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		consistentCompositeButton.setOnAction(e -> {
			try {
				new CompositeClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		hibernateButton.setOnAction(e -> {
			try {
				new HibernateClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
		springButton.setOnAction(e -> {
			try {
				new SpringClient().start(new Stage());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		});
	}
}
